package com.community.process._1010.dao.view;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableName;
import com.community.process._1010.common.base.BaseEntity;
import com.community.process._1010.common.utils.SystemAmountUtil;
import com.community.process._1010.dao.entity.ProcessTOrder;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 到餐加工主订单
 *
 * @author Zbs
 * @since 2024-09-05
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "到餐加工主订单")
public class ProcessTOrderView implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "主订单ID")
    private Long id;

    @Schema(description = "订单ID")
    private String tradeNo;

    @Schema(description = "主订单状态：1：未支付；2：已支付；3：买家关闭订单；4：超时未支付；5：商家关闭订单")
    private Integer mainStatus;

    @Schema(description = "订单状态：	    1-待确认/待支付，	    2-已支付，	    3-已发货，	    4-超时未支付，	    5-已收货，	    6-已完结/确认收货，	    7-申请退款中，	    8-发货前退款完结，	    9-发货后退款完结，	    10-收货后退款完结，	    11-退款完结，	    12-买家关闭订单，	    13-商家关闭订单")
    private Integer orderStatus;

    @Schema(description = "订单类型：1 自带食材单 2 成品菜订单 3 自组食材单")
    private Integer orderType;

    @Schema(description = "买家ID")
    private Long userId;

    @Schema(description = "商品名称")
    private String itemName;

    @Schema(description = "商品图片")
    private String itemImage;

    @Schema(description = "支付金额（单位：分）=商品价格+快递费-优惠券金额")
    private BigDecimal payAmount;

    @Schema(description = "实际支付金额（单位：分）=商品价格+快递费-优惠券金额")
    private BigDecimal actualPaymentAmount;

    @Schema(description = "快递费（单位：分）")
    private BigDecimal postAmount;

    @Schema(description = "优惠券金额（单位：分）")
    private BigDecimal couponAmount;

    @Schema(description = "优惠券ID")
    private List<Long> couponIds;

    @Schema(description = "手机号")
    private String phone;

    @Schema(description = "联系人")
    private String contactPerson;

    @Schema(description = "地区ID")
    private Long areaId;

    @Schema(description = "地区名称")
    private String areaName;

    @Schema(description = "市ID")
    private Long cityId;

    @Schema(description = "市名称")
    private String cityName;

    @Schema(description = "省ID")
    private Long provinceId;

    @Schema(description = "省名称")
    private String provinceName;

    @Schema(description = "收货详细地址")
    private String addr;

    @Schema(description = "退款原因")
    private String refundReason;

    @Schema(description = "拒绝退款原因")
    private String reason;

    @Schema(description = "拓展字段，根据需求填写")
    private String expandInfo;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "就餐时间")
    private String dinnerTime;

    @Schema(description = "店铺名称")
    private String shopName;

    @Schema(description = "店铺地址")
    private String detailedAddress;

    @Schema(description = "店铺id")
    private Long shopId;

    @Schema(description = "子订单列表（列表不会返回）")
    private List<ProcessOrderView> orderList;


    public ProcessTOrderView(ProcessTOrder tOrder) {
        this.id = tOrder.getId();
        this.tradeNo = tOrder.getTradeNo();
        this.mainStatus = tOrder.getMainStatus();
        this.orderStatus = tOrder.getOrderStatus();
        this.orderType = tOrder.getOrderType();
        this.userId = tOrder.getUserId();
        this.itemName = tOrder.getItemName();
        this.itemImage = tOrder.getItemImage();
        this.payAmount = SystemAmountUtil.pennyToYuan(tOrder.getPayAmount());
        this.actualPaymentAmount = SystemAmountUtil.pennyToYuan(tOrder.getActualPaymentAmount());
        this.postAmount = SystemAmountUtil.pennyToYuan(tOrder.getPostAmount());
        this.couponAmount = SystemAmountUtil.pennyToYuan(tOrder.getCouponAmount());
        this.couponIds = tOrder.getCouponIds() != null ? JSON.parseArray(tOrder.getCouponIds(), Long.class) : new ArrayList<>();
        this.phone = tOrder.getPhone();
        this.contactPerson = tOrder.getContactPerson();
        this.areaId = tOrder.getAreaId();
        this.areaName = tOrder.getAreaName();
        this.cityId = tOrder.getCityId();
        this.cityName = tOrder.getCityName();
        this.provinceId = tOrder.getProvinceId();
        this.provinceName = tOrder.getProvinceName();
        this.addr = tOrder.getAddr();
        this.refundReason = tOrder.getRefundReason();
        this.reason = tOrder.getReason();
        this.expandInfo = tOrder.getExpandInfo();
        this.createTime = tOrder.getCreateTime();
        this.shopId = tOrder.getShopId();
        this.shopName = tOrder.getShopName();
        this.detailedAddress = tOrder.getDetailedAddress();
        this.dinnerTime = tOrder.getDinnerTime();
    }
}
